//
//  StoreDetailUserWorksCell.m
//  BaseProject
//
//  Created by 王洋 on 2020/7/2.
//  Copyright © 2020 王洋. All rights reserved.
//

#import "StoreDetailImageShowCell.h"

#import "StoreDetailUserWorksCell.h"

@interface StoreDetailUserWorksCell ()<UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>{
    CGSize _cellSize;
    UIEdgeInsets _collectionEdge;
}

@end

@implementation StoreDetailUserWorksCell

+ (CGFloat)calculateHeight {

    CGFloat collectionWidth = TTScreenWidth - 30;
    CGFloat distance = 5;
    CGFloat simpleHeight = collectionWidth/3 - 2*distance;
    simpleHeight = simpleHeight + 2*distance + 55;

    return simpleHeight;
}

- (void)awakeFromNib {
    [super awakeFromNib];

    CGFloat width = TTScreenWidth - 30;
    
    CGFloat cellWidth;
    CGFloat distance = 5;
    cellWidth = width/3 - 2*distance;

    _cellSize =  CGSizeMake(cellWidth, cellWidth);
    _collectionEdge = UIEdgeInsetsMake(distance, distance, distance, distance);
    
    UICollectionViewFlowLayout *flowLaout = [[UICollectionViewFlowLayout alloc]init];
    flowLaout.scrollDirection = UICollectionViewScrollDirectionHorizontal;

    self.collectionview.collectionViewLayout = flowLaout;
    self.collectionview.delegate = self;
    self.collectionview.dataSource = self;
    self.collectionview.showsHorizontalScrollIndicator = NO;
    self.collectionview.showsVerticalScrollIndicator = NO;
    
    [self.collectionview registerNib:[UINib nibWithNibName:@"StoreDetailImageShowCell" bundle:nil] forCellWithReuseIdentifier:@"StoreDetailImageShowCellID"];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self.userIcon pp_clipCorners:UIRectCornerAllCorners radius:self.userIcon.frame.size.width/2];
    });
}

- (void)fillCellWithModel {
    
    [self.collectionview reloadData];
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    StoreDetailImageShowCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"StoreDetailImageShowCellID" forIndexPath:indexPath];
//    [cell fillCellWithModel:self.dataArray[indexPath.row]];

    return cell;
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 4;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    return _cellSize;
}

//设置cell的位置
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView
                       layout:(UICollectionViewLayout *)collectionViewLayout
       insetForSectionAtIndex:(NSInteger)section {

    return _collectionEdge;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {

}
@end
